package org.foj.control.commands.filters {
  
  import com.adobe.cairngorm.commands.ICommand;
  import com.adobe.cairngorm.control.CairngormEvent;
  
  import mx.collections.ArrayCollection;
  import mx.rpc.IResponder;
  
  import org.foj.control.events.filters.GetProjectsListEvent;
  import org.foj.model.PresentationModel;
  import org.foj.service.project.MockProjectDelegate;
  import org.foj.service.project.ProjectDelegate;

  public class GetProjectsListCommand implements ICommand, IResponder {
    
    private var presentationModel:PresentationModel;

    public function execute(event:CairngormEvent):void {
      this.presentationModel = (event as GetProjectsListEvent).getPresentationModel();
      var delegate:ProjectDelegate = new MockProjectDelegate(this);
      delegate.listProjects();
    }
    
    public function result(data:Object):void {
      
      presentationModel.allProjectsList = data.result as ArrayCollection;
      presentationModel.projectListSelectedIndex = 0;
    }
    
    public function fault(info:Object):void {
    }
    
  }
}